{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "aabb\n",
      "[1, 2, 10, 20]\n",
      "(1, 2, 10, 20)\n"
     ]
    }
   ],
   "source": [
    "# 1. 字符串 \n",
    "str1 = 'aa'\n",
    "str2 = 'bb'\n",
    "str3 = str1 + str2\n",
    "print(str3)  # aabb\n",
    "\n",
    "\n",
    "# 2. 列表 \n",
    "list1 = [1, 2]\n",
    "list2 = [10, 20]\n",
    "list3 = list1 + list2\n",
    "print(list3)  # [1, 2, 10, 20]\n",
    "\n",
    "# 3. 元组 \n",
    "t1 = (1, 2)\n",
    "t2 = (10, 20)\n",
    "t3 = t1 + t2\n",
    "print(t3)  # (10, 20, 100, 200)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "----------\n",
      "['hello', 'hello', 'hello', 'hello']\n",
      "('world', 'world', 'world', 'world')\n"
     ]
    }
   ],
   "source": [
    "# 1. 字符串\n",
    "print('-' * 10)  # ----------\n",
    "\n",
    "# 2. 列表\n",
    "list1 = ['hello']\n",
    "print(list1 * 4)  # ['hello', 'hello', 'hello', 'hello']\n",
    "\n",
    "# 3. 元组\n",
    "t1 = ('world',)\n",
    "print(t1 * 4)  # ('world', 'world', 'world', 'world')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "worldworldworldworld\n"
     ]
    }
   ],
   "source": [
    "t1 = ('world')\n",
    "print(t1 * 4)  # ('world', 'world', 'world', 'world')\n",
    "'''\n",
    "不加逗号，类型判断为唯一元素的类型\n",
    "'''"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n",
      "False\n",
      "True\n",
      "False\n",
      "False\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 1. 字符串\n",
    "print('a' in 'abcd')  # True\n",
    "print('a' not in 'abcd')  # False\n",
    "\n",
    "# 2. 列表\n",
    "list1 = ['a', 'b', 'c', 'd']\n",
    "print('a' in list1)  # True\n",
    "print('a' not in list1)  # False\n",
    "\n",
    "# 3. 元组\n",
    "t1 = ('a', 'b', 'c', 'd')\n",
    "print('aa' in t1)  # False\n",
    "print('aa' not in t1)  # True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 公共方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7\n",
      "4\n",
      "5\n",
      "3\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "# 1. 字符串\n",
    "str1 = 'abcdefg'\n",
    "print(len(str1))  # 7\n",
    "\n",
    "# 2. 列表\n",
    "list1 = [10, 20, 30, 40]\n",
    "print(len(list1))  # 4\n",
    "\n",
    "# 3. 元组\n",
    "t1 = (10, 20, 30, 40, 50)\n",
    "print(len(t1))  # 5\n",
    "\n",
    "# 4. 集合\n",
    "s1 = {10, 20, 30}\n",
    "print(len(s1))  # 3\n",
    "\n",
    "# 5. 字典\n",
    "dict1 = {'name': 'Rose', 'age': 18}\n",
    "print(len(dict1))  # 2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "ename": "NameError",
     "evalue": "name 'str1' is not defined",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mNameError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-6-534a2df91105>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mstr1\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;34m'abcdefg'\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      3\u001b[0m \u001b[1;32mdel\u001b[0m \u001b[0mstr1\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mstr1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m      5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      6\u001b[0m \u001b[1;31m# 2. 列表\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mNameError\u001b[0m: name 'str1' is not defined"
     ]
    }
   ],
   "source": [
    "# 1. 字符串\n",
    "str1 = 'abcdefg'\n",
    "del str1\n",
    "print(str1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[20, 30, 40]\n"
     ]
    }
   ],
   "source": [
    "# 2. 列表\n",
    "list1 = [10, 20, 30, 40]\n",
    "del(list1[0])\n",
    "print(list1)  # [20, 30, 40]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "g\n",
      "40\n"
     ]
    }
   ],
   "source": [
    "# 1. 字符串\n",
    "str1 = 'abcdefg'\n",
    "print(max(str1))  # g\n",
    "\n",
    "# 2. 列表\n",
    "list1 = [10, 20, 30, 40]\n",
    "print(max(list1))  # 40"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "a\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "# 1. 字符串\n",
    "str1 = 'abcdefg'\n",
    "print(min(str1))  # a\n",
    "\n",
    "# 2. 列表\n",
    "list1 = [10, 20, 30, 40]\n",
    "print(min(list1))  # 10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\t2\t3\t4\t5\t6\t7\t8\t9\t\n",
      " ********************\n",
      "1\t3\t5\t7\t9\t0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n"
     ]
    }
   ],
   "source": [
    "# 1 2 3 4 5 6 7 8 9\n",
    "for i in range(1, 10, 1):\n",
    "    print(i, end=\"\\t\")\n",
    "\n",
    "print('\\n',\"*\"*20)\n",
    "    \n",
    "# 1 3 5 7 9\n",
    "for i in range(1, 10, 2):\n",
    "    print(i, end=\"\\t\")\n",
    "\n",
    "# 0 1 2 3 4 5 6 7 8 9\n",
    "for i in range(10):\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(0, 'a')\n",
      "(1, 'b')\n",
      "(2, 'c')\n",
      "(3, 'd')\n",
      "(4, 'e')\n",
      "下标是1, 对应的字符是a\n",
      "下标是2, 对应的字符是b\n",
      "下标是3, 对应的字符是c\n",
      "下标是4, 对应的字符是d\n",
      "下标是5, 对应的字符是e\n"
     ]
    }
   ],
   "source": [
    "list1 = ['a', 'b', 'c', 'd', 'e']\n",
    "\n",
    "for i in enumerate(list1):\n",
    "    print(i)\n",
    "\n",
    "for index, char in enumerate(list1, start=1):\n",
    "    print(f'下标是{index}, 对应的字符是{char}')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 容器类型转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(10, 20, 30, 40, 50, 20)\n",
      "(100, 200, 300, 400, 500)\n"
     ]
    }
   ],
   "source": [
    "list1 = [10, 20, 30, 40, 50, 20]\n",
    "s1 = {100, 200, 300, 400, 500}\n",
    "\n",
    "print(tuple(list1))\n",
    "print(tuple(s1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['a', 'b', 'c', 'd', 'e']\n",
      "[100, 200, 300, 400, 500]\n"
     ]
    }
   ],
   "source": [
    "t1 = ('a', 'b', 'c', 'd', 'e')\n",
    "s1 = {100, 200, 300, 400, 500}\n",
    "\n",
    "print(list(t1))\n",
    "print(list(s1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{40, 10, 50, 20, 30}\n",
      "{'d', 'a', 'b', 'c', 'e'}\n"
     ]
    }
   ],
   "source": [
    "list1 = [10, 20, 30, 40, 50, 20]\n",
    "t1 = ('a', 'b', 'c', 'd', 'e')\n",
    "\n",
    "print(set(list1))\n",
    "print(set(t1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:root] *",
   "language": "python",
   "name": "conda-root-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
